package lumis.portal.file;

import lumis.portal.PortalException;

/**
 * Interface to validate a file.
 * 
 * <p>
 * It's possible make a custom class validator for a {@link IFileManager file repository}. 
 * For that, implement this interface, defining the validation behavior on the 
 * {@link #validate(FileConfig)} method.
 * </p>
 * <p>
 * To configure the custom validators used by file repositories, define, in the property bag 
 * of the file repository's service instance channel, a property named
 * <b>lumis.portal.file.validation.className</b>, having as its values the custom
 * validator class names.
 * </p>
 * <p>
 * Example custom validator class:
 * <code>
 * <pre>
 * public class FixedSizeValidator implements IFileValidator
 * {
 *   public void validate(FileConfig file) throws FileValidationException, PortalException
 *   {
 *     if (file.getFileSize() > 1000000)
 *       throw new FileValidationException("File size greater than 1000000"); // validation failed
 *   }
 * }
 * </pre>
 * </code>
 * 
 * @see IFileManager
 * 
 * @version $Revision: 13093 $ $Date: 2011-05-28 18:40:18 -0300 (Sat, 28 May 2011) $
 * @since 6.0.0
 */
public interface IFileValidator
{
	
	/**
	 * Validate the metadata of a file. This method executes in the same
	 * transactional context as the file inclusion. 
	 * @param file The file to be validated.
	 * @throws FileValidationException If the validation has failed.
	 * @throws PortalException If any error occurs validating the metadata.
	 * @since 6.0.0
	 */
	public void validate(FileConfig file) throws FileValidationException, PortalException;

}
